//
//  HomeViewController.m
//  QuickCure1
//
//  Created by maoge on 16/10/30.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "HomeViewController.h"
#import "LeftViewController.h"
#import "WeatherView.h"
#import "DoctorApplyView.h"
#import "DiseaseTypeFlowLayout.h"
#import "DiseaseTypeCell.h"
#import "HomePageDoctorApplyController.h"
#import "HomeChoiceProvinceVc.h"
#import "SDCycleScrollView.h"
#import "NoLoginView.h"
#import "HomeWebVc.h"
#import "UserManager.h"
#import "DirectionPointerController.h"
#import "HomeCycleWebVc.h"
#import "QRReadViewController.h"
#import "PlaneController.h"
#import "FlowView.h"



@interface HomeViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, SDCycleScrollViewDelegate,UIScrollViewDelegate>

@property (nonatomic, weak) UICollectionView *collectionView;
@property (nonatomic, weak) DoctorApplyView *applyView;
@property (nonatomic, weak) UIView *coverView;
@property (nonatomic, weak) UIControl *noLoginView;
@property (nonatomic, weak) UIView *cycleScrollView;
@property (nonatomic,weak) UIScrollView *scrollView;
//指南针视图
@property (nonatomic,weak) UIImageView *directionIV;
//飞机视图
@property (nonatomic,weak) UIImageView *planeIV;
@property (nonatomic,weak) UILabel *planeLb;

@property (nonatomic, weak) DiseaseTypeCell *cell;

//下拖判断
@property (nonatomic,assign) BOOL isScroll;
//上拖判断
@property (nonatomic,assign) BOOL isUpScroll;


@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
    
    _isScroll = YES;
    _isUpScroll = YES;
    
    
    //订阅选择地点按钮发出的被点击通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLocation) name:@"clickLocation" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(removeCoverView) name:@"buttonClicked" object:nil];
    
    //修改主页左侧按钮
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [leftBtn setImage:[UIImage imageNamed:@"医疗-2"] forState:UIControlStateNormal];
    
    [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [rightBtn setImage:[UIImage imageNamed:@"sao'yi'sao"] forState:UIControlStateNormal];
    
    [rightBtn addTarget:self action:@selector(clickRightBtnSao:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    
   
}

//点击了扫一扫
-(void)clickRightBtnSao:(UIButton *)sender{
    QRReadViewController *vc = [[QRReadViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)goBack {
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"leftBtnClicked" object:nil];
}


#pragma mark - 通知监听方法 跳转选择省份vc

- (void)changeLocation {
    
    [self.navigationController pushViewController:[[HomeChoiceProvinceVc alloc] init] animated:YES];
}



#pragma mark - 视图将要显示

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    _homeCityName = _weatherView.bt_location.titleLabel.text;
    
    [_weatherView setupLocationWithCity:_homeCityName];
    
    [_weatherView getWeatherDataWithCity:_homeCityName];
    
    [self.collectionView reloadData];
}



#pragma mark - 搭建UI

- (void)setupUI {
        
    self.title = @"超能快医";

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tecnoleg"]];

    self.navigationController.navigationBar.translucent = NO;
    
    //创建scrollView
    UIScrollView *scrollView = [[UIScrollView alloc]init];
    scrollView.delegate = self;
    [self.view addSubview:scrollView];
    self.scrollView = scrollView;

    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    
    ///天气view
    WeatherView *weatherView = [WeatherView weatherView];
    
    [scrollView addSubview:weatherView];
    
    
    ///轮播器
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(100, 100, 100, 100) delegate:self placeholderImage:[UIImage imageNamed:@"banner"]];
    
    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    
    [scrollView addSubview:cycleScrollView];
    
    NSArray *imagesArray = @[
                             @"http://img.guahao.com/portal_upload/rollingnews/1453447883150.jpg",
                             @"http://img.guahao.com/portal_upload/mediafocus/1461826474435.jpg",
                             @"http://img.guahao.com/portal_upload/rollingnews/1461574027543.jpg"
                             ];
    
    cycleScrollView.imageURLStringsGroup = imagesArray;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    
    [cycleScrollView addGestureRecognizer:tap];
    
    ///名医通
    DoctorApplyView *applyView = [DoctorApplyView applyView];
    
    [scrollView addSubview:applyView];
    
    ///创建疾病类型
    DiseaseTypeFlowLayout *layout = [[DiseaseTypeFlowLayout alloc] init];
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    
    [scrollView addSubview:collectionView];
    
    [collectionView registerNib:[UINib nibWithNibName:@"DiseaseTypeCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"diseaseType"];
    
    collectionView.dataSource = self;
    collectionView.delegate = self;
    
    collectionView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    
    //设置item与collectionView边框的间距
    collectionView.contentInset = UIEdgeInsetsMake(1, 0, 0.5, 0);
    collectionView.scrollEnabled = NO;
    
    
    
    //创建指南针图标视图
    UIImageView *direcPointImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"t01edf401c24385adf2"]];
    [self.view addSubview:direcPointImageView];
    self.directionIV = direcPointImageView;
    
    
    //一开始透明,小
    direcPointImageView.alpha = 0;
    direcPointImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);
    
    
    
    
    //创建飞机
    UIImageView *planeImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"hero1"]];
    [self.view addSubview:planeImageView];
    self.planeIV = planeImageView;
    
    //lable
    UILabel *planeLable = [[UILabel alloc]init];
    [self.view addSubview:planeLable];
    self.planeLb = planeLable;
    planeLable.text = @"继续上拉打飞机哦😯~~";
    planeLable.textColor = [UIColor orangeColor];
    planeLable.font = MYFONT(25);
    [planeLable sizeToFit];
    
    //一开始透明,小
    planeImageView.alpha = 0;
    planeImageView.transform = CGAffineTransformMakeScale(0.1, 0.1);
    
    planeLable.alpha = 0;
    
    
    //创建悬浮窗
    FlowView *flowView = [FlowView flowViewWithNIB];
    flowView.frame = CGRectMake(20, 400, 180, 190);
    
    
    
    
    
    
    
    
//    FlowButton *flowBtn = [FlowButton buttonWithType:UIButtonTypeCustom];
//    flowBtn.frame = CGRectMake(20, 400, 70, 70);
//    flowBtn.layer.cornerRadius = 35;
//    flowBtn.clipsToBounds = YES;
//    
//    [flowBtn setImage:[UIImage imageNamed:@"iq_topic_boy"] forState:UIControlStateNormal];
//    [flowBtn setImage:[UIImage imageNamed:@"iq_topic_girl"] forState:UIControlStateHighlighted];
////    flowBtn.userInteractionEnabled = NO;
    [[UIApplication sharedApplication].keyWindow addSubview:flowView];
    
    

    
    
    
    ///-----------------------------------------------------------------------------约束
    
    
    //指南针约束
    [direcPointImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(70);
        make.centerX.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(70, 70));
    }];
    
    //飞机约束
    [planeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-40);
        make.centerX.equalTo(self.view).offset(-110);
        make.size.mas_equalTo(CGSizeMake(80, 80));
    }];
    
    [planeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view).offset(60);
        make.bottom.equalTo(self.view).offset(-30);
    }];
    
    
    
    
    //scrollView约束
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    
    
    ///天气
    [weatherView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.mas_topLayoutGuideBottom);
        make.top.equalTo(scrollView);
        make.left.right.equalTo(scrollView);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.height.mas_equalTo(SCREEN_WIDTH / 7*3.7);
        
    }];
    
    ///轮播器
    [cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weatherView.mas_bottom);
        make.left.right.equalTo(scrollView);
        make.height.mas_equalTo(SCREEN_WIDTH / 7*3.7);
    }];
    
    ///名医通
    [applyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(cycleScrollView.mas_bottom);
        make.left.right.equalTo(scrollView);
        make.height.mas_equalTo(SCREEN_WIDTH / 10*1);
    }];
    
    ///疾病
    [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(applyView.mas_bottom);
        make.left.right.equalTo(scrollView);
        make.bottom.equalTo(scrollView);
        make.height.mas_equalTo(SCREEN_WIDTH / 10*7);
    }];
    
    
    
    
    ///关联
    _weatherView = weatherView;
    _cycleScrollView = cycleScrollView;
    _applyView = applyView;
    _collectionView = collectionView;
}

//跳转到轮播器网页
- (void)tap {
    
    [self.navigationController pushViewController:[[HomeCycleWebVc alloc] init] animated:YES];
}



#pragma mark - Collection view data source

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 3;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    DiseaseTypeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"diseaseType" forIndexPath:indexPath];
    
    cell.count = indexPath.section * 2 + indexPath.item;
    
    cell.tag = indexPath.section * 2 + indexPath.item;
    
    cell.backgroundColor = [UIColor whiteColor];
    
    cell.contentView.transform = CGAffineTransformMakeScale(0, 0);
    [UIView animateWithDuration:0.75 delay:cell.count/1.5 usingSpringWithDamping:0.25 initialSpringVelocity:1 options:UIViewAnimationOptionAllowUserInteraction animations:^{
        cell.contentView.transform = CGAffineTransformIdentity;
    } completion:nil];
    
    //关键帧动画 设置大小
    CAKeyframeAnimation *keyAnim = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    
    //变化节点,重复次数
    keyAnim.values = @[@(1), @(0.9), @(1)];
    keyAnim.repeatCount = CGFLOAT_MAX;
    keyAnim.duration = 2;
    
    [cell.iv_icon.layer addAnimation:keyAnim forKey:nil];
    
    return cell;
}



#pragma mark - Collection view delegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    DiseaseTypeCell *cell = (DiseaseTypeCell *)[collectionView cellForItemAtIndexPath:indexPath];
    
    //如果点击最后一个cell
    if (cell.tag == 5) {
        
        //跳转到公益活动链接
        [self.navigationController pushViewController:[[HomeWebVc alloc] init] animated:YES];
        
    }
    else {
        
//        //解档 查看是否登录
//        NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"userInfo.plist"];
//        
//        Users *us = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
//        
//        LeftViewController *leftVc = [[LeftViewController alloc] init];
        
    
        
        if ( [MLDefaults objectForKey:kIsUserLoginKey]) {
            
            //跳转到名医通
            HomePageDoctorApplyController *vc = [[HomePageDoctorApplyController alloc]init];
            
            DiseaseTypeCell *cell =( DiseaseTypeCell *) [collectionView cellForItemAtIndexPath:indexPath];
            
            ///给名益通属性赋值 耦合性太强,应将传值放在init方法中
            vc.labStr =  cell.lb_type.text;
            vc.num = cell.tag;
            
            [self.navigationController pushViewController:vc animated:YES];
        
        }
        else {
            
            [self setupNoLoginView];
        }
    }
}



#pragma mark - 未登录点击名医通view

- (void)setupNoLoginView {
    
    UIView *coverView = [[UIView alloc] initWithFrame:KeyWindow.frame];
    
    [self.view addSubview:coverView];
    
    coverView.backgroundColor = [UIColor blackColor];
    
    coverView.alpha = 0.5;
    
    //弹框view
    NoLoginView *noLoginV = [NoLoginView noLoginView];
    
    [self.view insertSubview:noLoginV aboveSubview:coverView];
    
    //弹框初始位置约束
    [noLoginV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(SCREEN_WIDTH / 7*3);
        make.left.equalTo(self.view).offset(70);
        make.right.equalTo(self.view).offset(-70);
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_top);
    }];
    
    [self.view layoutIfNeeded];
    
    //更新约束
    [noLoginV mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_top).offset(SCREEN_HEIGHT / 2 + noLoginV.height / 3);
    }];
    
    //动画掉下来
    [UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:0 animations:^{

        [self.view layoutIfNeeded];
        
    } completion:^(BOOL finished) {
        
        
    }];
    
    [noLoginV addTarget:self action:@selector(removeCoverView) forControlEvents:UIControlEventValueChanged];
    
    _coverView = coverView;
    _noLoginView = noLoginV;
    
}

- (void)removeCoverView {
    
    [_noLoginView removeFromSuperview];
    [_coverView removeFromSuperview];
}


#pragma mark
#pragma mark - scroll代理方法
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat offsetY1 = scrollView.contentOffset.y;
    
    //下拖
    
    if(offsetY1 < 0){
        CGFloat offsetY = ABS(scrollView.contentOffset.y);
        
        if(_isScroll){
            if(offsetY > 50){
                
                CGFloat newOffsetY = offsetY - 50;
                CGFloat proportion = newOffsetY / 100;
                //        NSLog(@"%f",proportion);
                self.directionIV.alpha = proportion;
                self.directionIV.transform = CGAffineTransformMakeScale(proportion, proportion);
                [self.directionIV mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.top.equalTo(self.view).offset(50 + proportion * 50 - 64);
                }];
                
                
                
                
                if(proportion > 1){
                    
                    NSLog(@"%f",self.scrollView.contentOffset.y);
                    _isScroll = NO;
                    self.scrollView.scrollEnabled = NO;
                    
                    [self.scrollView setContentOffset:CGPointMake(0, -152.0)];
                    
                    [self.scrollView setContentOffset:CGPointMake(0, -SCREEN_HEIGHT) animated:YES];
                    
                    
                    //拔到KeyWindow上
                    UIWindow *currentKeyWindow = [UIApplication sharedApplication].keyWindow;
                    
                    UIImageView *directionIV = self.directionIV;
                    [directionIV removeFromSuperview];
                    //
                    [currentKeyWindow addSubview:directionIV];
                    
                    
                    [directionIV mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.top.equalTo(currentKeyWindow).offset(130);
                        make.centerX.equalTo(currentKeyWindow);
                    }];
                    
                    [currentKeyWindow layoutIfNeeded];
                    
                    
                    
                    [UIView animateWithDuration:1.0 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
                        directionIV.transform = CGAffineTransformMakeScale(1.5, 1.5);
                    } completion:^(BOOL finished) {
                        //第二层动画
                        //创建覆盖层View
                        UIView *coverView = [[UIView alloc]initWithFrame:SCREEN_BOUNDS];
                        [self.view addSubview:coverView];
                        coverView.backgroundColor = [UIColor blackColor];
                        coverView.alpha = 0;
                        
                        [UIView animateWithDuration:1.5 delay:1 options:UIViewAnimationOptionAllowUserInteraction animations:^{
                            coverView.alpha = 1;
                            
                            [directionIV mas_updateConstraints:^(MASConstraintMaker *make) {
                                make.top.equalTo(currentKeyWindow).offset(SCREEN_HEIGHT/2);
                                
                            }];
                            [currentKeyWindow layoutIfNeeded];
                        } completion:^(BOOL finished) {
                            //第三层
                            
                            [UIView animateWithDuration:2.0 animations:^{
                                directionIV.transform = CGAffineTransformMakeScale(13, 13);
                                
                            }completion:^(BOOL finished) {
                                
                                self.scrollView.userInteractionEnabled = YES;
                                self.scrollView.contentOffset = CGPointMake(0, -64);
                                self.scrollView.scrollEnabled = YES;
                                
                                [coverView removeFromSuperview];
                                
                                //modal切换控制器
                                DirectionPointerController *direPointer = [[DirectionPointerController alloc]init];
                                
                                [self presentViewController:direPointer animated:NO completion:nil];
                                
                                //第四层
                                [UIView animateWithDuration:0.5 animations:^{
                                    directionIV.alpha = 0;
                                    
                                }completion:^(BOOL finished) {
                                    //指南针约束恢复
                                    [directionIV removeFromSuperview];
                                    [self.view addSubview:directionIV];
                                    [directionIV mas_makeConstraints:^(MASConstraintMaker *make) {
                                        make.top.equalTo(self.view).offset(70);
                                        make.centerX.equalTo(self.view);
                                        make.size.mas_equalTo(CGSizeMake(70, 70));
                                    }];
                                    directionIV.transform = CGAffineTransformMakeScale(0.1, 0.1);
                                    _isScroll = YES;
                                }];
                                
                            }];
                        }];
                    }];
                    
                    
                    
                    return;
                }
                
            }else{
                self.directionIV.alpha = 0;
                self.directionIV.transform = CGAffineTransformMakeScale(0.1, 0.1);
            }
            
            
            
            
        }
    }
    
    
    //上拖
    else{
        CGFloat offsetY = scrollView.contentOffset.y;
        
        if(_isUpScroll){
            if(offsetY > SCREEN_HEIGHT/3.5){
                
                CGFloat newOffsetY = offsetY - SCREEN_HEIGHT/3.5;
                
                NSLog(@"%f",newOffsetY);
                CGFloat proportion = newOffsetY / 100;
                //        NSLog(@"%f",proportion);
                self.planeIV.alpha = proportion;
                self.planeIV.transform = CGAffineTransformMakeScale(proportion, proportion);
                [self.planeIV mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.bottom.equalTo(self.view).offset(- proportion * 30);
                }];
                

                if(proportion > 1){
                    
                    _isUpScroll = NO;
                    self.scrollView.scrollEnabled = NO;
                    
                    [self.scrollView setContentOffset:CGPointMake(0, 300.0)];
                    
                    [self.scrollView setContentOffset:CGPointMake(0, SCREEN_HEIGHT) animated:YES];
                    
                    //拔到KeyWindow上
                    UIWindow *currentKeyWindow = [UIApplication sharedApplication].keyWindow;
                    
                    UIImageView *planeIV = self.planeIV;
                    [planeIV removeFromSuperview];
                    
                    [currentKeyWindow addSubview:planeIV];
                    //在keyWindow上部署约束
                    [planeIV mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.bottom.equalTo(currentKeyWindow).offset(- 30);
                        make.centerX.equalTo(currentKeyWindow).offset(-110);
                        make.size.mas_equalTo(CGSizeMake(80, 80));
                    }];
                    
                    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:100 options:UIViewAnimationOptionAllowUserInteraction animations:^{
                        planeIV.transform = CGAffineTransformMakeScale(1.25, 1.25);
                        
                        self.planeLb.alpha = 0;
                    } completion:^(BOOL finished) {
                        
                        //第二层动画  屏幕变黑 飞到中央
                        UIView *coverView = [[UIView alloc]initWithFrame:SCREEN_BOUNDS];
                        [currentKeyWindow insertSubview:coverView belowSubview:planeIV];
                        coverView.backgroundColor = [UIColor blackColor];
                        
                        coverView.alpha = 0;
                        
                        [UIView animateWithDuration:2 animations:^{
                            coverView.alpha = 1;
                        }];
                        
                        [planeIV mas_updateConstraints:^(MASConstraintMaker *make) {
                            make.centerX.equalTo(currentKeyWindow);
                            make.bottom.equalTo(currentKeyWindow).offset(-SCREEN_HEIGHT/2 + 39.6);
                        }];
                        
                        
                        
                        [UIView animateWithDuration:3 animations:^{
                            [currentKeyWindow layoutIfNeeded];
                            planeIV.transform = CGAffineTransformScale(planeIV.transform, 0.5, 0.6);
                        } completion:^(BOOL finished) {
                            //第三层 切换控制器
                            PlaneController *planeVC = [[PlaneController alloc]init];
                            [self presentViewController:planeVC animated:NO completion:nil];
                            planeVC.view.userInteractionEnabled = NO;
                            [UIView animateWithDuration:1 delay:0.5 options:UIViewAnimationOptionAllowUserInteraction animations:^{
                                coverView.alpha = 0;
                            } completion:^(BOOL finished) {
                                
                                //指南针约束恢复
                                [planeIV removeFromSuperview];
                                [self.view addSubview:planeIV];
                                [planeIV mas_makeConstraints:^(MASConstraintMaker *make) {
                                    make.bottom.equalTo(self.view).offset(-40);
                                    make.centerX.equalTo(self.view).offset(-110);
                                    make.size.mas_equalTo(CGSizeMake(80, 80));
                                }];
                                planeIV.transform = CGAffineTransformMakeScale(0.1, 0.1);
                                planeIV.alpha = 0;
                                _isUpScroll = YES;

                                self.scrollView.scrollEnabled = YES;
                                
                                [coverView removeFromSuperview];
                                
                                planeVC.view.userInteractionEnabled = YES;
                                
                            }];
                            
                        }];
                        
                    }];

                    
                }
            
            }else{
                self.planeIV.alpha = 0;
                self.planeIV.transform = CGAffineTransformMakeScale(0.1, 0.1);
            }
        }
    
    }
    
    //设置Lable的显示隐藏
    if(offsetY1 > SCREEN_HEIGHT/4.0){
        
        if(offsetY1 < SCREEN_HEIGHT/3.5){
            self.planeLb.alpha = (offsetY1 - SCREEN_HEIGHT/4.0) / 20;
        }else{
            self.planeLb.alpha = 1;
        }
    }else{
        self.planeLb.alpha = 0;
    }
    
    
    
    
}




- (void)dealloc {
    NSLog(@"主页释放");
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


@end


































